﻿using IntelligentAgriculture.Domain.Entity;
using IntelligentAgriculture.Domain.Interface;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using IntelligentAgriculture.Domain;

namespace IntelligentAgriculture.Domain.Impl
{
    public class UserRepository : IUserRepository
    {
        private readonly AgricultureDbContext _context;

        public UserRepository(AgricultureDbContext context)
        {
            _context = context;
        }
        /// <summary>
        /// 获取用户信息
        /// </summary>
        /// <returns>获取用户信息</returns>
        public IQueryable<Userinfo> GetUsers()
        {
            return _context.Userinfos.AsQueryable().AsNoTracking()/*.Where(p=>p.IsDeleted==false)*/;
        }
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="UserName">用户名</param>
        /// <param name="PassWord">密码</param>
        /// <returns>返回登录信息</returns>
        public Userinfo? Login(string userName, string pwd)
        {
            return _context.Userinfos.FirstOrDefault(p => p.Uname == userName && p.Upwd == pwd/* && p.IsDeleted == false*/);
        }
        /// <summary>
		/// 新增人员信息
		/// </summary>
		/// <param name="info">新增信息</param>
		/// <returns>返回受影响行数</returns>
		public async Task<int> AddUser(Userinfo info)
        {
            _context.Userinfos.Add(info);
            return await _context.SaveChangesAsync();
        }
    }
}
